package ua.kpi.flats.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import ua.kpi.flats.dao.UserDao;
import ua.kpi.flats.entity.User;

@Repository("userDao")
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Autowired
	public UserDaoImpl(HibernateTemplate hibernateTemplate) {
		super.setHibernateTemplate(hibernateTemplate);
	}
	
	@Transactional(readOnly = true,
			       isolation = Isolation.READ_COMMITTED)
	public User getUser(String userName) {
		return (User) getHibernateTemplate().find("SELECT u FROM User u WHERE u.username = ?",userName).get(0);
	}

}
